package com.tfriend.framework.xml;

import java.util.Map;

public class Dataset {
	private String name="";
	private String type="";
	private Map rows = new CaseInsensitiveHashMap();
	
	public String getType() {
		return nvl(type);
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public String getName() {
		return nvl(name);
	}
	
	public void setName(String name) {
		this.name = name.toUpperCase();
	}
	
	public Map getRows() {
		return rows;
	}
	
	public void addRow(Row row) {
		this.rows.put(row.getN(), row);
	}
	
	public int maxRows() {
		return rows.size();
	}
	
	public Row getRow(int n) throws Exception{
		if (n <= 0) throw new Exception("Index number start from number 1.");
		return (Row)rows.get(Integer.toString(n));
	}
	
	public int getColumnCount() throws Exception {
		return getRow(1).getColSize();
	}
	
	public String[] getColumnNames() throws Exception {
		return getRow(1).getColNames();
	}
	
	public String getColumn(int i, String name) throws Exception {
		return getRow(i).getCol(name.toUpperCase()).getValue();
	}
	
	String nvl(String param) {
		return param != null ? param: "";
	}
}
